package com.tms.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tms.springboot.base.pojo.PdTransportLine;
import com.tms.springboot.base.pojo.PdTransportLineType;
import com.tms.springboot.mapper.PdTransportLineMapper;
import com.tms.springboot.service.PdTransportLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 线路表 服务实现类
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@Service
public class PdTransportLineServiceImpl extends ServiceImpl<PdTransportLineMapper, PdTransportLine> implements PdTransportLineService {

    @Autowired
    private PdTransportLineMapper transportLineMapper;

    @Override
    public PageInfo<PdTransportLine> queryByConditionAndPage(Integer currentPage, Integer pageSize, PdTransportLine transportLine) {
        LambdaQueryWrapper<PdTransportLine> wrapper = new LambdaQueryWrapper<>();

        if (transportLine.getLineNumber() != null) {
            wrapper.like(PdTransportLine::getLineNumber, transportLine.getLineNumber());
        }

        if (transportLine.getName() != null) {
            wrapper.like(PdTransportLine::getName, transportLine.getName());
        }

        if (transportLine.getTransportLineTypeId() != null && !transportLine.getTransportLineTypeId().equals("")) {
            wrapper.eq(PdTransportLine::getTransportLineTypeId, transportLine.getTransportLineTypeId());
        }

        PageHelper.startPage(currentPage, pageSize);

        return new PageInfo<>(transportLineMapper.selectList(wrapper));
    }
}
